<script type="text/javascript" src="paging.js"></script>
<!-- Danh sách sẽ có phân trang -->
<?php
	include_once "../classes/giaovien_bs.php";
	include_once "../classes/chucvu_bs.php";
	
	$Keyword = trim($_GET['key']);
	$Page    = trim($_GET['pag']);
	
	$GiaoVien = new giaovien_bs();
	if(trim($Keyword) != "")
		$GiaoVien->SetHoTen(trim($Keyword));
	$DGiaoVien = $GiaoVien->LayDanhSach();
	
	
	//$Total = ($DGiaoVien == null) ? 0 : count($DGiaoVien);
	
	$Limit = 20; //Element Per Page
	$SoTrang = ceil(count($DGiaoVien) / $Limit);
	
	$DGiaoVien = $GiaoVien->LayDanhSachPaging(($Page - 1) * $Limit, $Limit);
?>
<div class="Paging">
	<?php
		if($DGiaoVien != null)
		{
			if($Page > 1)
				echo "<a class='AjaxPage' href='#' onclick='javascript:loadXMLGiaoVien(\"$Keyword\",1);'>Đầu</a>";	
			for($i = 1; $i <= $SoTrang; $i++)
			{
				if($Page - 5 <= $i && $i <= $Page + 5)
				{
					if($i == $Page)
						echo "<a class='AjaxPageCur' href='#' onclick='javascript:loadXMLGiaoVien(\"$Keyword\",$i);'>$i</a>";
					else
						echo "<a class='AjaxPage' href='#' onclick='javascript:loadXMLGiaoVien(\"$Keyword\",$i);'>$i</a>";
				}
				elseif($i == $Page + 6)
					echo "<a class='AjaxPage' href='#' onclick='javascript:loadXMLGiaoVien(\"$Keyword\",$i);'>...</a>";
				elseif($i == $Page - 6)
					echo "<a class='AjaxPage' href='#' onclick='javascript:loadXMLGiaoVien(\"$Keyword\",$i);'>...</a>";
			}
			if($Page < $SoTrang)
				echo "<a class='AjaxPage' href='#' onclick='javascript:loadXMLGiaoVien(\"$Keyword\",$SoTrang);'>Cuối</a>";	
			
			echo "<span style='float:right; background-color:#4ABDF4; color: #FFF; padding:0px 3px'>Trang $Page/$SoTrang</span>";
		}
	?>
</div>

<div class="TableList">
	
	<div id="result">
		<table width="100%" class="DSGV">
			<tr>
				<th rowspan="2" class="first">STT</th>
				<th rowspan="2" width="70px">Mã giáo viên</th>
				<th rowspan="2" colspan="2">Họ tên</th>
				<th rowspan="2">Nữ</th>
				<th rowspan="2">Ngày sinh<br />(d/M/y)</th>
				<th rowspan="2">Điện thoại</th>
				<th rowspan="2">Email</th>
				<th colspan="3" class="ColSpan">Tùy chọn khác</th>
				<th rowspan="2">Lập <br />HĐ</th>
			</tr>
			<tr>
				<th class="Op">Chi tiết</th>
				<th class="Op">Chỉnh sửa</th>
				<th class="Op">Xóa</th>
			</tr>
			<!-- Lấy danh sách học viên từ cơ sở dữ liệu -->
			<?php
				if($DGiaoVien == null)
				{
					echo '<tr><td colspan="12" align="center"> Nội dung rỗng</td></tr>';
				}
				else
				{
					for($i = 0; $i < count($DGiaoVien); $i++)
					{
						$HT = TachHoTen($DGiaoVien[$i]['HoTen']);
						$LinkDetails = 'index.php?act=giaovien_chitiet&id=' . $DGiaoVien[$i]['MaGiaoVien'] . '&pin=' . $DGiaoVien[$i]['PIN'];
						$LinkEdit = 'index.php?act=giaovien_capnhat&id=' . $DGiaoVien[$i]['MaGiaoVien'] . '&pin=' . $DGiaoVien[$i]['PIN'];
						$LinkTrash = 'index.php?act=giaoien_xoa_sub&id=' . $DGiaoVien[$i]['MaGiaoVien'] . '&pin=' . $DGiaoVien[$i]['PIN'];
						echo '<tr class="ButtonDetails" id="' . $DGiaoVien[$i]['MaGiaoVien'] . '">';
							echo '<td align="center"><b>' . (($Page - 1) * $Limit + ($i + 1)) . '</b></td>';
							echo '<td>' . $DGiaoVien[$i]['MaGiaoVien'] . '</td>';
							echo '<td>' . $HT[0] . '</td>';
							echo '<td>' . $HT[1] . '</td>';
							echo '<td align="center">';
								echo '<input type="checkbox" disabled="true" id="c' . $i . '" class="css-checkbox" ' . ($DGiaoVien[$i]['GioiTinh'] == 1 ? 'checked="true"' : '') . '/>';
								echo '<label for="c' . $i . '" class="css-labelCheckbox"></label>';
							echo '</td>';
							echo '<td>' . ConvertDate($DGiaoVien[$i]['NgaySinh']) . '</td>';
							echo '<td align="right">' . DinhDangSDT($DGiaoVien[$i]['DienThoai']) . '</td>';
							echo '<td> ' . $DGiaoVien[$i]['Email'] . ' </td>';
							echo '<td align="center"><a href="' . $LinkDetails . '" title="Thông tin chi tiết về \'' . $DGiaoVien[$i]['HoTen'] . '\'"><img src="../data/details.png" alt="" /></a></td>';
							echo '<td align="center"><a href="' . $LinkEdit . '" title="Cập nhật thông tin của \'' . $DGiaoVien[$i]['HoTen'] . '\'"><img src="../data/edit.png" alt="" /></a></td>';
							echo '<td align="center"><a href="' . $LinkTrash . '" title="Xóa \'' . $DGiaoVien[$i]['HoTen'] . '\'"><img src="../data/delete.png" alt="" /></a></td>';
							echo '<td align="center"><a href="index.php?act=hopdong_them&mgv=' . $DGiaoVien[$i]['MaGiaoVien'] . '&pin=' . $DGiaoVien[$i]['PIN'] . '" title="Lập hợp đồng mới với GV \'' . $DGiaoVien[$i]['HoTen'] . '\'"><img src="../data/add_hopdong.png" alt="" /></a></td>';
						echo '</tr>';
					}
				}
			?>
		</table>
	</div>
	
</div>